package com.molichuxing.gateway.bff.goods.convertor;

import com.molichuxing.framework.dto.Paged;
import com.molichuxing.gateway.bff.goods.response.GoodsBaseVo;
import com.molichuxing.gateway.bff.goods.response.GoodsDetailVo;
import com.molichuxing.gateway.bff.goods.response.GoodsVo;
import com.molichuxing.services.business.dto.request.create.GoodsExclusiveCreateDto;
import com.molichuxing.services.business.dto.request.create.GoodsSubscribeCreateDto;
import com.molichuxing.services.business.dto.request.create.GoodsSubscribePackageCreateDto;
import com.molichuxing.services.business.dto.response.GoodsBaseBizDto;
import com.molichuxing.services.business.dto.response.GoodsBizBizDto;
import com.molichuxing.services.business.dto.response.GoodsDetailBizDto;
import com.molichuxing.services.property.GoodsMileageTypeEnum;
import com.molichuxing.services.property.GoodsPaymentTypeEnum;
import com.molichuxing.services.property.GoodsTypeEnum;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 转换类
 * @author xuelin yi
 */
public class Convert {

	/********************************************商品属性信息转换 开始 *****************************/
	public static Paged<GoodsVo> toGoodsPage(Paged<GoodsBizBizDto> page, Map<Integer, String> vehicleMap) {
		Paged<GoodsVo> result = null;;
		if(null != page) {
			result = new Paged<>();
			BeanUtils.copyProperties(page, result);
			result.setList(toGoodsVo(page.getList(), vehicleMap));
			result.setTab(page.getTab());
		}
		return result;
	}

	public static List<GoodsVo> toGoodsVo(List<GoodsBizBizDto> beanList, Map<Integer, String> vehicleMap) {
		List<GoodsVo> dtoList = null;
		if (beanList != null && beanList.size() > 0) {
			dtoList = new ArrayList<>();
			for (GoodsBizBizDto bean : beanList) {
				dtoList.add(toGoodsVo(bean, vehicleMap));
			}
		}
		return dtoList;
	}

	public static GoodsVo toGoodsVo(GoodsBizBizDto bean, Map<Integer, String> vehicleMap) {
		GoodsVo beanDto = null;
		if (bean != null) {
			beanDto = new GoodsVo();
			BeanUtils.copyProperties(bean, beanDto);
			beanDto.setUseVehicleTime(bean.getUseVehicleTime()+"");
			if(null != vehicleMap && (null != vehicleMap.get(bean.getGoodsId()))) {
				beanDto.setVehicleStyleStr(vehicleMap.get(bean.getGoodsId()));
			}
		}
		return beanDto;
	}
	/********************************************商品信息转换 结束 *****************************/

	/********************************************商品基础信息转换 开始 *****************************/
	public static GoodsBaseVo toGoodsBaseVo(GoodsBaseBizDto bean, String goodsPicture) {
		GoodsBaseVo beanDto = null;
		if (bean != null) {
			beanDto = new GoodsBaseVo();
			BeanUtils.copyProperties(bean, beanDto);
			beanDto.setGoodsPicture(goodsPicture);
			beanDto.setUseVehicleTime(bean.getUseVehicleTime()+"");
		}
		return beanDto;
	}

	public static GoodsDetailVo toGoodsDetailVo(GoodsDetailBizDto bean) {
		GoodsDetailVo beanDto = null;
		if (bean != null) {
			beanDto = new GoodsDetailVo();
			BeanUtils.copyProperties(bean, beanDto);
		}
		return beanDto;
	}
	/********************************************商品基础信息转换 结束 *****************************/
}
